<?php
namespace app\api\controller;
use app\tplay\lib\TplayPro;
use think\exception\HttpResponseException;
use app\tplay\lib\exception\ApiException;
use think\Cache;

class Base extends TplayPro
{
	public $domain = '';//域名
	public $param;
    protected function _initialize()
    {
        header('Access-Control-Allow-Origin:*');
        header('Access-Control-Allow-Methods:POST');
        header('Access-Control-Allow-Headers:x-requested-with,content-type');
        
        parent::_initialize();
        // 首先需要获取headers
        $param = $this->request->param();
        // 基础参数校验
        if(empty($param['sign'])) {
            throw new ApiException('sign不存在', 400);
        }
        // 需要sign
        if(!$this->checkSign($param)) {
            throw new ApiException('授权码sign失败', 401);
        }
//        把获取数据的sign缓存起来,做唯一性验证
        Cache::set($param['sign'], 1, config('app.app_sign_cache_time'));
        
        $this->param = $this->checkSign($param);
    }
}
